package com.txsj.scan.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.txsj.scan.R;
import com.txsj.scan.bean.GoodsInfo;
import com.txsj.scan.utils.glide.GlideImgManager;

import java.util.ArrayList;
import java.util.List;

/**
 * @Created by WangChuangJun on 2018/12/7
 * @Describe
 */
public class SettledGoodsAdapter extends RecyclerView.Adapter<SettledGoodsAdapter.SettledGoodsViewHolder> {

    private Context context;
    private List<GoodsInfo> list;

    public SettledGoodsAdapter(Context context) {
        this.context = context;
        this.list = new ArrayList<>();
    }

    public void setList(List<GoodsInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public SettledGoodsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SettledGoodsViewHolder(LayoutInflater.from(context).inflate(R.layout.item_settled_goods,parent,false));
    }

    @Override
    public void onBindViewHolder(SettledGoodsViewHolder holder, int position) {
        holder.bind(list.get(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SettledGoodsViewHolder extends RecyclerView.ViewHolder {

        ImageView iv_goods_img;
        TextView tv_goods_name;
        RecyclerView itemRecyclerView;

        public SettledGoodsViewHolder(View itemView) {
            super(itemView);
            iv_goods_img = (ImageView)itemView.findViewById(R.id.iv_goods_img);
            tv_goods_name = (TextView) itemView.findViewById(R.id.tv_goods_name);
            itemRecyclerView = (RecyclerView)itemView.findViewById(R.id.recyclerViewItem);
        }

        public void bind(GoodsInfo goodsInfo){
            GlideImgManager.getLoadImg(context,goodsInfo.getGoods_img(),iv_goods_img);
            tv_goods_name.setText(goodsInfo.getGoods_name());
            itemRecyclerView.setLayoutManager(new LinearLayoutManager(context));
            itemRecyclerView.setAdapter(new EpcAdapter(context,goodsInfo.getEpcList()));
        };
    }
}
